package com.yantong.quartz.job;

import com.yantong.service.TicketService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * 优惠券定时任务
 * @author kanghaixin
 * @date 2018/9/29.14:33
 */
@Service
public class TicketTimer {
    private static Logger logger = LoggerFactory.getLogger(TicketTimer.class);
    @Autowired
    private TicketService ticketService;

        private boolean taskOn = true;
    /**
     * 优惠券失效检查
     */
    @Scheduled(cron = "0 0 */1 * * ?")
    public void checkTicket() {
        if (!taskOn) {
            logger.info("system task set off!checkTicket!");
            return;
        }
        logger.info("checkTicket start...");
        int result = ticketService.checkTicket();
        logger.info("checkTicket end ...,disable num:{}", result);
    }

    /**
     * 优惠券失效提醒
     */
//    @Scheduled(cron = "0 03 17 ? * *")
    @Scheduled(cron = "0 10 22 ? * *")
    public void checkTicketMessage() {
        if (!taskOn) {
            logger.info("system task set off!checkTicket!");
            return;
        }
        logger.info("checkTicketMessage start...");
        int result = ticketService.sendTicketOvertimeMessage();
        logger.info("complete ,send message:{}", result);
    }
}
